package com.ruoyi.system.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysContractMapper;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.CollectionUtils;

/**
 * 合同Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-16
 */
@Service
public class SysContractServiceImpl implements ISysContractService
{
    @Autowired
    private SysContractMapper sysContractMapper;

    /** 线索客户service接口层 */
    @Autowired
    private ISysCustomerService sysCustomerService;

    /** 合同明细service接口层 */
    @Autowired
    private ISysContractLabelService sysContractLabelService;

    /** 合同支付明细service接口层 */
    @Autowired
    private ISysContractPayLabelService sysContractPayLabelService;

    /** 业绩分配service接口层 */
    @Autowired
    private ISysContractSpdService sysContractSpdService;

    /** 合同日志service接口层 */
    @Autowired
    private ISysContractLogService sysContractLogService;

    /** 审核人 */
    @Autowired
    private ISysRoleService sysRoleService;

    /**
     * 查询合同
     *
     * @param id 合同主键
     * @return 合同
     */
    @Override
    public SysContract selectSysContractById(Long id)
    {
        SysContract sysContract = sysContractMapper.selectSysContractById(id);

        if (null != sysContract){
            //查询合同明细
            SysContractLabel sysContractLabel = new SysContractLabel();
            sysContractLabel.setContractId(id);
            List<SysContractLabel> sysContractLabelList = sysContractLabelService.selectSysContractLabelList(sysContractLabel);
            if (!CollectionUtils.isEmpty(sysContractLabelList))
            {
                sysContract.setSysContractLabelList(sysContractLabelList);
            }
            //查询合同支付明细
            List<SysContractPayLabel> sysContractPayLabelList = sysContractPayLabelService.selectSysContractPayLabelByContractId(sysContract.getId());
            if (!CollectionUtils.isEmpty(sysContractPayLabelList)){
                sysContract.setSysContractPayLabelList(sysContractPayLabelList);
            }
            //查询业绩分配
            List<SysContractSpd> sysContractSpdList = sysContractSpdService.selectSysContractSpdListByContractId(sysContract.getId());
            if (!CollectionUtils.isEmpty(sysContractSpdList)){
                sysContract.setSysContractSpdList(sysContractSpdList);
            }
            //查询合同日志
            List<SysContractLog> sysContractLogList = sysContractLogService.selectSysContractLogListByContractId(sysContract.getId());
            if (!CollectionUtils.isEmpty(sysContractLogList)){
                sysContract.setSysContractLogList(sysContractLogList);
            }
        }

        return sysContract;
    }

    /**
     * 查询此客户只存在新签合同
     * @param customerId
     * @return
     */
    @Override
    public SysContract selectNewSysContractByCustomerId(Long customerId) {
        return sysContractMapper.selectNewSysContractByCustomerId(customerId);
    }

    /**
     * 根据合同编号查询合同
     * @param contractCode
     * @return
     */
    @Override
    public SysContract selectSysContractByContractCode(String contractCode) {
        return sysContractMapper.selectSysContractByContractCode(contractCode);
    }

    /**
     * 查询合同列表
     *
     * @param sysContract 合同
     * @return 合同
     */
    @Override
    @DataScope(deptAlias = "d",userAlias = "u")
    public List<SysContract> selectSysContractList(SysContract sysContract)
    {
        return sysContractMapper.selectSysContractList(sysContract);
    }

    /**
     * 修改班主任
     * @param sysContract
     * @return
     */
    @Override
    @Transactional
    public int updateTeacher(SysContract sysContract) {
        int status = 0;
        try {
            //修改班主任方法
            status = this.updateSysContract(sysContract);

            //构建合同日志
            SysContractLog sysContractLog = sysContractLogService.buildSysContractLog(sysContract.getId(), "修改班主任");

            //新增合同日志
            sysContractLogService.insertSysContractLog(sysContractLog);
        }
        catch (Exception e){
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new RuntimeException(e.getMessage());
        }
        return 0;
    }

    /**
     * 新增合同
     *
     * @param sysContract 合同
     * @return 结果
     */
    @Override
    @Transactional
    public int insertSysContract(SysContract sysContract)
    {
        int status = 0;
        try {
            //判空方法
            emptyInsertSysContract(sysContract);

            //查询用户
            SysCustomer sysCustomer = sysCustomerService.selectSysCustomerByCustomerId(sysContract.getCustomerId());
            if(null == sysCustomer){
                throw new RuntimeException("用户未查询到，请联系管理员");
            }
            //修改用户状态
            sysCustomer.setStatus(1L);
            sysCustomerService.updateSysCustomer(sysCustomer);

            //构建合同
            sysContract = buildSysContract(sysContract);

            status = sysContractMapper.insertSysContract(sysContract);

            //构建合同日志
            SysContractLog sysContractLog = sysContractLogService.buildSysContractLog(sysContract.getId(), "创建合同");

            //新建合同日志
            sysContractLogService.insertSysContractLog(sysContractLog);
        }catch (Exception e){
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new RuntimeException(e.getMessage());
        }
        return status;
    }

    /**
     * 构建合同实体
     * @param sysContract
     * @return
     */
    @Override
    public SysContract buildSysContract(SysContract sysContract) {
        //创建时间
        sysContract.setCreateTime(DateUtils.getNowDate());
        //创建人
        sysContract.setCreateBy(SecurityUtils.getUsername());
        //sysContract.setCreateBy("admin");
        //合同状态
        sysContract.setStatus(0L);
        //合同确认状态
        sysContract.setContractConfirmStatus(0L);
        //合同金额
        sysContract.setContractMoney(new BigDecimal(0));
        //剩余金额
        sysContract.setRemainingMoney(new BigDecimal(0));
        //剩余课时
        sysContract.setRemainingClassTime(0L);
        //已支付金额
        sysContract.setPayMoney(new BigDecimal(0));
        //是否在读
        sysContract.setIsStudying(0L);
        return sysContract;
    }

    /**
     * 新增客户判空方法
     * @param sysContract
     */
    @Override
    public void emptyInsertSysContract(SysContract sysContract) {
        //线索客户主键
        if (null == sysContract.getCustomerId()){
            throw new RuntimeException("未传输线索客户主键");
        }
        //查询客户是否存在
        SysCustomer sysCustomer = sysCustomerService.selectSysCustomerByCustomerId(sysContract.getCustomerId());
        if (null == sysCustomer){
            throw new RuntimeException("线索客户不存在，请联系管理员");
        }

        //合同编号
        if (StringUtils.isEmpty(sysContract.getContractCode())) {
            throw new RuntimeException("合同编号未填写");
        }
        //查询是否存在相同合同编号的数据
        SysContract queryContract = this.selectSysContractByContractCode(sysContract.getContractCode());
        if (null != queryContract){
            throw new RuntimeException("系统中存在相同的合同编号");
        }

        //校区
        if (null == sysContract.getCampusId()){
            throw new RuntimeException("校区未选择");
        }
        //合同属性
        if (null == sysContract.getContractAttribute()){
            throw new RuntimeException("未选择合同属性");
        }
        //合同属性(新建)
        if (sysContract.getContractAttribute() == 0){
            SysContract queryNewSysContract = this.selectNewSysContractByCustomerId(sysContract.getCustomerId());
            if(null != queryNewSysContract){
                throw new RuntimeException("客户:" + sysCustomer.getCustomerName() + "，已存在新签合同，合同属性不可继续选择新签合同");
            }
        }
        else {
            SysContract queryNewSysContract = this.selectNewSysContractByCustomerId(sysContract.getCustomerId());
            if (null == queryNewSysContract){
                throw new RuntimeException("客户：" + sysCustomer.getCustomerName() + "不存在新签合同，请选择新签合同");
            }
        }
        //合同类型
        if (null == sysContract.getContractType()){
            throw new RuntimeException("合同类型未选择");
        }
        //开始日期
        if (null == sysContract.getBeginTime()){
            throw new RuntimeException("开始日期未填");
        }
        //周期
        if (null == sysContract.getWeek()){
            throw new RuntimeException("周期未填");
        }
        //是否推荐(是)
        if (sysContract.getIsReferrer() == 1){
            if (null == sysContract.getReferrerId()){
                throw new RuntimeException("是否推荐为是时，推荐人必填");
            }
        }
        //签约者
        if (null == sysContract.getSignerId()){
            throw new RuntimeException("请选择签约者");
        }
        //签约日期
        if (null == sysContract.getSignerTime()){
            throw new RuntimeException("签约日期未填写");
        }
    }

    /**
     * 修改合同剩余金额
     * @param sysContractId
     * @param money
     * @return
     */
    @Override
    public BigDecimal updateSysContractRemainingMoney(Long sysContractId, BigDecimal money,Boolean isAdd) {
        //查询合同判断是否存在
        SysContract sysContract = this.selectSysContractById(sysContractId);
        if (null == sysContract){
            throw new RuntimeException("合同不存在，请联系管理员");
        }
        //增加
        if (isAdd){
            sysContract.setRemainingMoney(sysContract.getRemainingMoney().add(money));
        }
        //减少
        if (!isAdd){
            sysContract.setRemainingMoney(sysContract.getRemainingMoney().subtract(money));
        }
        this.updateSysContract(sysContract);
        return sysContract.getRemainingMoney();
    }

    /**
     * 修改剩余课时
     * @param sysContractId
     * @param time
     * @param isAdd
     * @return
     */
    @Override
    public Long updateSysContractRemainingClassTime(Long sysContractId, Long time, Boolean isAdd) {
        //查询合同判断是否存在
        SysContract sysContract = this.selectSysContractById(sysContractId);
        if (null == sysContract){
            throw new RuntimeException("合同不存在，请联系管理员");
        }
        //增加
        if (isAdd){
            sysContract.setRemainingClassTime(sysContract.getRemainingClassTime() + time);
        }
        //减少
        if (!isAdd){
            sysContract.setRemainingClassTime(sysContract.getRemainingClassTime() + time);
        }
        this.updateSysContract(sysContract);
        return sysContract.getRemainingClassTime();
    }

    /**
     * 修改合同金额
     * @param sysContractId
     * @param money
     * @param isAdd
     * @return
     */
    @Override
    public BigDecimal updateSysContractMoney(Long sysContractId, BigDecimal money, Boolean isAdd) {
        //查询合同判断是否存在
        SysContract sysContract = this.selectSysContractById(sysContractId);
        if (null == sysContract){
            throw new RuntimeException("合同不存在，请联系管理员");
        }
        //增加
        if (isAdd){
            sysContract.setContractMoney(sysContract.getContractMoney().add(money));
        }
        //减少
        if (!isAdd){
            sysContract.setContractMoney(sysContract.getContractMoney().subtract(money));
        }
        this.updateSysContract(sysContract);
        return sysContract.getContractMoney();
    }

    /**
     * 修改合同支付金额
     * @param sysContractId
     * @param money
     * @param isAdd
     * @return
     */
    @Override
    public BigDecimal updateSysContractPayMoney(Long sysContractId, BigDecimal money, Boolean isAdd) {
        //查询合同判断是否存在
        SysContract sysContract = this.selectSysContractById(sysContractId);
        if (null == sysContract){
            throw new RuntimeException("合同不存在，请联系管理员");
        }
        //增加
        if (isAdd){
            sysContract.setPayMoney(sysContract.getPayMoney().add(money));
        }
        //减少
        if (!isAdd){
            sysContract.setPayMoney(sysContract.getPayMoney().subtract(money));
        }
        this.updateSysContract(sysContract);
        return sysContract.getContractMoney();
    }

    /**
     * 修改合同
     *
     * @param sysContract 合同
     * @return 结果
     */
    @Override
    public int updateSysContract(SysContract sysContract)
    {
        return sysContractMapper.updateSysContract(sysContract);
    }

    /**
     * 批量删除合同
     *
     * @param ids 需要删除的合同主键
     * @return 结果
     */
    @Override
    public int deleteSysContractByIds(Long[] ids)
    {
        try {

        }
        catch (Exception e){

        }

        return sysContractMapper.deleteSysContractByIds(ids);
    }

    /**
     * 删除合同信息
     *
     * @param id 合同主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteSysContractById(Long id)
    {
        int state = 0;
        try {
            //判断合同是否可删除
            emptyDeleteSysContract(id);

            //删除合同明细
            sysContractLabelService.deleteSysContractLabelByContractId(id);

            //删除付费明细
            sysContractPayLabelService.deleteSysContractPayLabelByContractId(id);

            //删除合同日志
            sysContractLogService.deleteSysContractLogByContractId(id);

            //合同删除方法
            state = sysContractMapper.deleteSysContractById(id);
        }
        catch (Exception e){
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new RuntimeException(e.getMessage());
        }
        return state;
    }

    /**
     * 判断删除合同方法
     * @param id
     */
    @Override
    public void emptyDeleteSysContract(Long id) {
        SysContract sysContract = this.selectSysContractById(id);
        if (null == sysContract){
            throw new RuntimeException("未查询到合同信息，请联系管理员");
        }

        //判断是否为新合同
        if (sysContract.getStatus() != 0){
            throw new RuntimeException("当前合同不为新合同不可删除");
        }
    }

    /**
     * 出纳审核
     * @param sysContract
     * @return
     */
    @Override
    @Transactional
    public int cashierApply(SysContract sysContract) {
        int status = 0;
        try {
            //判断当前用户角色是否为出纳
            List<SysRole> sysRoles = sysRoleService.selectRoleEntityListByUserId(SecurityUtils.getUserId());
            if (CollectionUtils.isEmpty(sysRoles)) {
                throw new RuntimeException("当前用户角色为空");
            }
            boolean flag = false;
            for (int i = 0; i < sysRoles.size(); i++) {
                SysRole sysRole = sysRoles.get(i);
                if (sysRole.getRoleKey().equals("cashier")){
                    flag = true;
                }
            }
            if (!flag){
                throw new RuntimeException("当前用户不为出纳不可进行此操作");
            }
            //查询合同，查询已付金额是否满
            SysContract queryContract = this.selectSysContractById(sysContract.getId());
            if (null == queryContract){
                throw new RuntimeException("合同未查询到，请联系管理员");
            }
            if (queryContract.getContractMoney().compareTo(queryContract.getPayMoney()) == 1){
                throw new RuntimeException("金额未付满，出纳不可进行确认");
            }
            //判断状态是否为提交状态
            if (queryContract.getContractConfirmStatus() != 1){
                throw new RuntimeException("当前状态不为提交态，请确认");
            }
            //审核状态(出纳已审核)
            queryContract.setContractConfirmStatus(2L);
            //出纳审核时间
            queryContract.setCashierApproveTime(DateUtils.getNowDate());
            //出纳人
            queryContract.setCashierId(SecurityUtils.getUserId());
            //修改时间
            queryContract.setUpdateTime(DateUtils.getNowDate());
            //修改人
            queryContract.setUpdateBy(SecurityUtils.getUsername());
            //修改
            status = this.updateSysContract(queryContract);
            //新增操作日志
            SysContractLog sysContractLog = new SysContractLog();
            //操作日志创建人
            sysContractLog.setCreateBy(SecurityUtils.getUsername());
            //操作日志创建时间
            sysContractLog.setCreateTime(DateUtils.getNowDate());
            //操作日志操作方式
            sysContractLog.setOperate("出纳已确认");
            //合同
            sysContractLog.setContractId(sysContract.getId());
            sysContractLogService.insertSysContractLog(sysContractLog);
        }
        catch (Exception e){
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new RuntimeException(e.getMessage());
        }
        return status;
    }

    /**
     * 出纳取消审核
     * @param sysContract
     * @return
     */
    @Override
    @Transactional
    public int cashierUnApply(SysContract sysContract) {
        int status = 0;
        try {
            //判断当前用户角色是否为出纳
            List<SysRole> sysRoles = sysRoleService.selectRoleEntityListByUserId(SecurityUtils.getUserId());
            if (CollectionUtils.isEmpty(sysRoles)) {
                throw new RuntimeException("当前用户角色为空");
            }
            boolean flag = false;
            for (int i = 0; i < sysRoles.size(); i++) {
                SysRole sysRole = sysRoles.get(i);
                if (sysRole.getRoleKey().equals("cashier")){
                    flag = true;
                }
            }
            if (!flag){
                throw new RuntimeException("当前用户不为出纳不可进行此操作");
            }
            //查询合同
            SysContract querySysContract = this.selectSysContractById(sysContract.getId());
            if (null == querySysContract){
                throw new RuntimeException("合同未查询到，请联系管理员");
            }
            //判断状态是否为出纳已确认
            if (querySysContract.getContractConfirmStatus() != 2){
                throw new RuntimeException("当前状态不为出纳已审核，请确认");
            }
            //开立状态
            querySysContract.setContractConfirmStatus(1L);
            //出纳人
            querySysContract.setCashierId(null);
            //出纳时间
            querySysContract.setCashierApproveTime(null);
            //修改时间
            querySysContract.setUpdateTime(DateUtils.getNowDate());
            //修改人
            querySysContract.setUpdateBy(SecurityUtils.getUsername());
            //进行修改
            status = this.updateSysContract(querySysContract);
            //新增操作日志
            SysContractLog sysContractLog = new SysContractLog();
            //操作日志创建人
            sysContractLog.setCreateBy(SecurityUtils.getUsername());
            //操作日志创建时间
            sysContractLog.setCreateTime(DateUtils.getNowDate());
            //操作日志方式
            sysContractLog.setOperate("出纳取消确认");
            //合同主键
            sysContractLog.setContractId(querySysContract.getId());
            //新增合同操作日志
            sysContractLogService.insertSysContractLog(sysContractLog);
        }
        catch (Exception e){
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new RuntimeException(e.getMessage());
        }
        return status;
    }

    /**
     * 校长审核方法
     * @param sysContract
     * @return
     */
    @Override
    @Transactional
    public int principalApprove(SysContract sysContract) {
        int status = 0;
        try {
            //判断是否为校长
            List<SysRole> sysRoles = sysRoleService.selectRoleEntityListByUserId(SecurityUtils.getUserId());
            if (CollectionUtils.isEmpty(sysRoles)) {
                throw new RuntimeException("该用户未有角色不可进行操作");
            }
            boolean flag = false;
            for (int i = 0; i < sysRoles.size(); i++) {
                SysRole sysRole = sysRoles.get(i);
                if (sysRole.getRoleKey().equals("principal")){
                    flag = true;
                }
            }
            if (!flag){
                throw new RuntimeException("当前用户不为校长，不可进行此操作");
            }
            //查询合同，查询已付金额是否满
            SysContract queryContract = this.selectSysContractById(sysContract.getId());
            if (null == queryContract){
                throw new RuntimeException("合同未查询到，请联系管理员");
            }
            if (queryContract.getContractMoney().compareTo(queryContract.getPayMoney()) == 1){
                throw new RuntimeException("金额未付满，校长不可进行确认");
            }
            //判断状态是否为提交状态
            if (queryContract.getContractConfirmStatus() != 2){
                throw new RuntimeException("当前状态不为出纳已确认，请确认");
            }
            //审核状态(校长已审核)
            queryContract.setContractConfirmStatus(3L);
            //校长审核时间
            queryContract.setPrincipalApproveTime(DateUtils.getNowDate());
            //出纳人
            queryContract.setPrincipalId(SecurityUtils.getUserId());
            //修改时间
            queryContract.setUpdateTime(DateUtils.getNowDate());
            //修改人
            queryContract.setUpdateBy(SecurityUtils.getUsername());
            //修改
            status = this.updateSysContract(queryContract);
            //新增操作日志
            SysContractLog sysContractLog = new SysContractLog();
            //操作日志创建人
            sysContractLog.setCreateBy(SecurityUtils.getUsername());
            //操作日志创建时间
            sysContractLog.setCreateTime(DateUtils.getNowDate());
            //操作日志操作方式
            sysContractLog.setOperate("校长已确认");
            //合同
            sysContractLog.setContractId(sysContract.getId());
            sysContractLogService.insertSysContractLog(sysContractLog);
        }
        catch (Exception e){
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new RuntimeException(e.getMessage());
        }
        return status;
    }

    /**
     * 校长取消审核
     * @param sysContract
     * @return
     */
    @Override
    @Transactional
    public int principalUnApprove(SysContract sysContract) {
        int status = 0;
        try {
            //判断是否为校长
            List<SysRole> sysRoles = sysRoleService.selectRoleEntityListByUserId(SecurityUtils.getUserId());
            if (CollectionUtils.isEmpty(sysRoles)) {
                throw new RuntimeException("该用户未有角色不可进行操作");
            }
            boolean flag = false;
            for (int i = 0; i < sysRoles.size(); i++) {
                SysRole sysRole = sysRoles.get(i);
                if (sysRole.getRoleKey().equals("principal")){
                    flag = true;
                }
            }
            if (!flag){
                throw new RuntimeException("当前用户不为校长，不可进行此操作");
            }
            //查询合同，查询已付金额是否满
            SysContract queryContract = this.selectSysContractById(sysContract.getId());
            if (null == queryContract){
                throw new RuntimeException("合同未查询到，请联系管理员");
            }
            if (queryContract.getContractMoney().compareTo(queryContract.getPayMoney()) == 1){
                throw new RuntimeException("金额未付满，校长不可进行确认");
            }
            //判断状态是否为提交状态
            if (queryContract.getContractConfirmStatus() != 3){
                throw new RuntimeException("当前状态不为校长已确认不可操作，请确认");
            }
            //审核状态(待出纳确认)
            queryContract.setContractConfirmStatus(2L);
            //校长审核时间
            queryContract.setPrincipalApproveTime(null);
            //出纳人
            queryContract.setPrincipalId(null);
            //修改时间
            queryContract.setUpdateTime(DateUtils.getNowDate());
            //修改人
            queryContract.setUpdateBy(SecurityUtils.getUsername());
            //修改
            status = this.updateSysContract(queryContract);
            //新增操作日志
            SysContractLog sysContractLog = new SysContractLog();
            //操作日志创建人
            sysContractLog.setCreateBy(SecurityUtils.getUsername());
            //操作日志创建时间
            sysContractLog.setCreateTime(DateUtils.getNowDate());
            //操作日志操作方式
            sysContractLog.setOperate("校长取消确认");
            //合同
            sysContractLog.setContractId(sysContract.getId());
            sysContractLogService.insertSysContractLog(sysContractLog);
        }catch (Exception e){
            //事务回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new RuntimeException(e.getMessage());
        }
        return status;
    }


    /**
     * 提交方法
     * @param sysContract
     * @return
     */
    @Override
    @Transactional
    public int submit(SysContract sysContract) {
        int status = 0;
        try {
            //查询合同
            sysContract = this.selectSysContractById(sysContract.getId());
            //判断是否可提交
            if (sysContract.getContractConfirmStatus() != 0){
                throw new RuntimeException("当前状态不为新合同不可提交");
            }

            sysContract.setContractConfirmStatus(1L);
            //修改
            this.updateSysContract(sysContract);

            //日志
            SysContractLog sysContractLog = new SysContractLog();
            sysContractLog.setContractId(sysContract.getId());

            //操作日志创建人
            sysContractLog.setCreateBy(SecurityUtils.getUsername());
            //操作日志创建时间
            sysContractLog.setCreateTime(DateUtils.getNowDate());
            //操作日志操作方式
            sysContractLog.setOperate("提交合同");
            status = sysContractLogService.insertSysContractLog(sysContractLog);
        }
        catch (Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new RuntimeException(e.getMessage());
        }
        return status;
    }
}